#ifdef WIN32
#include "CTNull.h"
#else
#include <mysql.h>
#include <my_global.h>
#include <my_sys.h>
#endif
#include "CTMySQLCharset.h"

CTMySQLCharset::CTMySQLCharset() : m_pstCharset(NULL)
{
    InitCharset();
}

/** 设定字符集 */
int CTMySQLCharset::InitCharset(const char* pszCharsetName)
{
    m_pstCharset = get_charset_by_csname(pszCharsetName, MY_CS_PRIMARY, 0);
    return (m_pstCharset != NULL ? 0 : -1);
}

/** 转义 */
int CTMySQLCharset::EscapeString(char* pszDst, unsigned int uiDstLen,
    const char* pszSrc, unsigned int uiSrcLen)
{
	/*
		RETURN VALUES
		(size_t) -1 The escaped string did not fit in the to buffer
		#           The length of the escaped string
	*/
    return escape_string_for_mysql(m_pstCharset, pszDst, uiDstLen,
        pszSrc, uiSrcLen);
}

CHARSET_INFO* CTMySQLCharset::GetCharset() const
{
    return m_pstCharset;
}
